{layout name="main"/}
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title">
                    <h5>所有{$type?:'文章'}</h5>
                    <div class="ibox-tools">
                        <a href="{:url('admin/article/add')}" class="btn btn-primary btn-xs">发布{$type}</a>
                    </div>
                </div>
                <div class="ibox-content">

                    <div class="row m-b-sm m-t-sm">
                        <div class="col-sm-4">
                            <a href="{:url('admin/article/showlist')}" class="btn-sm btn {:input('type')?'btn-default':input('type')=='0'?'btn-default':'btn-info'}"><i class="fa fa-list"></i> 所有</a>
                            <a href="{:url('admin/article/showlist',['type'=>0])}" class="btn-sm btn {:input('type')=='0'?'btn-info':'btn-default'}"><i class="fa fa-clock-o"></i> 公司公告</a>
                            <a href="{:url('admin/article/showlist',['type'=>1])}" class="btn-sm btn {:input('type')=='1'?'btn-info':'btn-default'}"><i class="fa fa-lock"></i> 今日要闻</a>
                        </div>
<!--                        <div class="col-md-1">
                            <button type="button" id="loading-example-btn" class="btn btn-white btn-sm" onclick='reload()'><i class="fa fa-refresh"></i> 刷新</button>
                        </div>-->
                        <div class="col-md-8">
                            <div class="input-group">
                                <input type="text" placeholder="请输入{$type}标题" class="input-sm form-control" name=keyword value="{$keyword}"> <span class="input-group-btn">
                                <button type="button" class="btn btn-sm btn-primary" onclick="search()">搜索</button> </span>
                            </div>
                        </div>
                    </div>

                    <div class="project-list">

                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
                            <thead>
                                <tr  role="row">
                                    <th>类型</th>
                                    <th style=" width: 30%">标题</th>

                                    <th>发布日期</th>
                                    <th>置顶</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                              {:table_empty_list($list,'暂无数据!',6)}
                                {volist name='list' id='article'}
                                <tr>
                                    <td>
                                        {$article.type}
                                    </td>
                                    <td>
                                        <a href="{:url('admin/Article/view',['id'=>$article.article_id])}">{$article.title}</a>
                                    </td>

                                    <td>
                                        {$article.publish_date}
                                    </td>
                                    <td>
                                        {if condition='$article.is_top == 1'}
                                        <span class="label label-primary">已置顶
                                        </span> {else}
                                        <span class="label label-default">未置顶
                                          </span> {/if}
                                    </td>
                                    <td class="project-status">
                                        {if condition='$article.is_avaible == 1'}
                                        <span class="label label-primary">有效
                                        </span> {else}
                                        <span class="label label-default">无效
                                          </span> {/if}
                                    </td>
                                    <td>
                                        <a href="{:url('admin/Article/edit',['article_id'=>$article.article_id])}" class="btn btn-info btn-sm"><i class="fa fa-pencil"></i> 编辑 </a>
                                        <button class="btn btn-success btn-sm" onclick="settop({$article.article_id},this)"><i class="fa fa-arrows-v"></i> 更改置顶 </button>
                                        <button class="btn btn-warning btn-sm" onclick="setava({$article.article_id},this)"><i class="fa fa-check"></i> 更改可用性 </button>
                                        <button class="btn btn-danger btn-sm" onclick="deletearticle({$article.article_id})"><i class="fa fa-trash"></i> 删除 </button>
                                    </td>
                                </tr>
                                {/volist}
                            </tbody>

                        </table>

                                           <div class="row">
                                        <div class="col-sm-6">
                                            <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all">
                                                每页显示 {:getPageSize()} 项，共 {$list->toArray()['total']} 项</div></div>
                                        <div class="col-sm-6">
                                            <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                                {$list->render()}

                                            </div>

                                        </div>
                                    </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<script src="js/content.min.js?v=1.0.0"></script>
<script>
    function deletearticle(id) {
        post({
            url: "{:url('admin/Article/del',[],'')}" + '/article_id/' + id,
            success: function(res) {
                swal({
                    title: 'success',
                    text: res.message,
                    type: "success"
                }, function() {
                    reload();
                });
            },
            error: function(error) {
                swal("错误", JSON.parse(error.responseText).message, "error");
            }
        });
    }
    function setava(id) {
        post({
            url: "{:url('admin/Article/setava',[],'')}" + '/article_id/' + id,
            success: function(res) {
                swal({
                    title: 'success',
                    text: res.message,
                    type: "success"
                }, function() {
                    reload();
                });
            },
            error: function(error) {
                swal("错误", JSON.parse(error.responseText).message, "error");
            }
        });
    }
    function settop(id) {
        post({
            url: "{:url('admin/Article/settop',[],'')}" + '/article_id/' + id,
            success: function(res) {
                swal({
                    title: 'success',
                    text: res.message,
                    type: "success"
                }, function() {
                    reload();
                });
            },
            error: function(error) {
                swal("错误", JSON.parse(error.responseText).message, "error");
            }
        });
    }
    function search() {
        var keyword = $("input[name=keyword]").val();
        toUrl("{:url('admin/Article/showlist', ['type'=>$type], '')}/keyword/" + keyword);
    }
</script>
